package user;

import java.sql.ResultSet;
import java.sql.SQLException;


public class LoginValidation {
	private User user;
	private String type;
	
	public LoginValidation(User user, String type) {
		this.user = user;
		this.type = type;
	}
		
	public boolean isValidate() {
		String pw = getTruePassword();
		return user.getPassword().equals(pw);
	}
	
	public String getTruePassword() {		
		return user.getTruePassword();
	}
	
    
    public static String getUserId(String username) {
    	DBConnector db = DBConnector.getDBConnector();
    	db.prepareStatement("select cus_ID from customer where cus_login_name = ?");
    	db.bindParameter(username);	
    	try {
    		ResultSet result = db.queryPstmt();
			if(result.next()) {
				return result.getString(1);
			} else
				return null;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return null;
    }
    
    public static String getRestaurantId(String restname) {
    	DBConnector db = DBConnector.getDBConnector();
    	db.prepareStatement("select rest_ID from restaurant where rest_login_name = ?");
    	db.bindParameter(restname);	
    	try {
    		ResultSet result = db.queryPstmt();
			if(result.next()) {
				return result.getString(1);
			} else
				return null;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return null;    
    }   
}
